define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/complaint/index' + location.search,
                    add_url: 'order/complaint/add',
                    // edit_url: 'order/complaint/edit',
                    del_url: 'order/complaint/del',
                    multi_url: 'order/complaint/multi',
                    import_url: 'order/complaint/import',
                    table: 'complaint',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                escape:false,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'personal.account', title: __('Personal.account'), operate: 'LIKE'},
                        {field: 'gid', title: __('Gid')},
                        {field: 'sn', title: __('Sn'), operate: 'LIKE'},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'),searchList: {"1":__('待回复'),"2":__('已回复')}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'sendtime', title: __('Sendtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
            //             {field: 'reply_content', title: __('Reply_content'), operate: 'LIKE',
            //             cellStyle:function (value, row, index) {
            //                 return {
            //                     css: {
            //                         "min-width": "100px",
            //                         "white-space": "nowrap",
            //                         "text-overflow": "ellipsis",
            //                         "overflow": "hidden",
            //                         "max-width": "240px",
            //                         "cursor": "pointer"
            //                     }
            //                 }
            //             },
            // },
                        {field: 'replytime', title: __('Replytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                        name: 'answer',
                                        text: __(''),
                                        title: __('回复'),
                                        classname: 'btn btn-xs btn-info btn-dialog',
                                        icon: 'fa fa-commenting',
                                        url: 'order/complaint/edit',
    
                                    },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        answer: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
